/*
 * Package il.ac.biu.cs.grossmm.cpp
 * File Cpp.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.api.cpp;

import il.ac.biu.cs.grossmm.api.keys.Key;
import il.ac.biu.cs.grossmm.api.presence.Entity;

/**
 * An interface implemented by a CPP service providers, which are part of the
 * framework.
 * <p>
 * CPP service provider receives subscribe requests from a CPP service consumer
 * (which implements <tt>CppServiceConsumer</tt> interface) and sends
 * notifictions by invoking <tt>CppServiceConsumer.notify</tt> method.
 * <p>
 * When an application wants to subscribe to information associated with some
 * resource, such as the presence information associated with a PRESENTITY (in
 * order to receive periodic notifications of this information), it invokes the
 * subscribe operation.
 * 
 * <pre>
 *        +-----------+                    +-----------+
 *        |           |                    |           |
 *        |   CPP     |                    |    CPP    |
 *        | service   | -- subscribe ----&gt; |  service  |
 *        | consumer  |                    |  provider |
 *        |           |                    |           |   
 *        +-----------+                    +-----------+
 * </pre>
 * 
 * The subscribe operation has the following attributes: watcher, target,
 * duration and SubscriptID. The 'watcher' identifiers the WATCHER entity to
 * receive notifications. The 'target' identifies target of the subscription by
 * specifying a data key representing this target. The duration specifies the
 * maximum number of seconds that the SUBSCRIPTION should be active (which may
 * be zero, in which case this is a one-time request for presence information).
 * The SubscriptID creates a reference to the SUBSCRIPTION that is used when
 * unsubscribing. SubscriptID should not be longer than 40 characters.
 * 
 * <p>
 * CPP service provider is obtained and linked to CPP sevrice provider by
 * invoking <tt>CppServiceManager.getServiceProvider</tt> method
 */
public interface CppServiceProvider<T> {
	/**
	 * Subscribes a watcher for peridoic notification about changes in
	 * information associated with a resource
	 * 
	 * @param watcher
	 *            the watcher to receive notifications
	 * @param target
	 *            the key specyfing the target of the subscription
	 * @param subscriptID
	 *            a globally unique identifier of this subscription
	 * @param duration
	 *            duration of the subscrption, if this value is zero, then
	 *            subscription is discarded after the first notification
	 * @return state of the subscription
	 */
	State subscribe(Entity watcher, Key target, String subscriptID, int duration);
}
